import React, { useEffect, useState } from 'react';
import { Radio, Switch } from 'antd';
import axios from '../api/axios';
let { Group } = Radio;

export default (props) => {
  const [fapiao, setValue] = useState();
  const [h5, setH5] = useState(true);
  const onChange = (checked) => {
    console.log(`switch to ${checked}`);
    if (fapiao == 2) {
      setH5(checked);
    }
  };
  const onChange1 = (e) => {
    console.log('radio checked', e.target.value);
    setValue(e.target.value);
    if (e.target.value == 1 || e.target.value == 3) {
      setH5(false);
    } else {
      setH5(true);
      
    }
  };

  useEffect(() => {
    axios.get('http://127.0.0.1:5502/data.json').then((res) => {
      console.log(res.AppBizExt);
      let num = res.AppBizExt.sendInvoiceMail;
      setValue(num);
      if (num == 1 || num == 3) {
        setH5(false);
      } else {
        setH5(true);
      }
    });
  }, []);

  return (
    <div>
      发票发送方：
      <Group onChange={onChange1}>
        <Radio value={1}>享道</Radio>
        <Radio value={2}>合作方</Radio>
        <Radio value={3}>123</Radio>
      </Group>
      <br />
      H5消息推送： <Switch checked={h5} onChange={onChange} />
    </div>
  );
};
